package com.uzhie.web.service.listener;

import org.apache.activemq.command.ActiveMQDestination;
import org.springframework.jms.core.JmsTemplate;

import javax.jms.BytesMessage;

/**
 * Created by TangFei on 2018/10/11.
 */
public class MQFTPSendService implements MQSendService {

    private ActiveMQDestination mqDestination;
    private JmsTemplate jmsTemplate;

    @Override
    public void setMqDestination(ActiveMQDestination mqDestination) {
        this.mqDestination = mqDestination;
    }

    @Override
    public void setJmsTemplate(JmsTemplate jmsTemplate) {
        this.jmsTemplate = jmsTemplate;
    }

    @Override
    public void sendMessage(Integer queue, String ID, byte[] body) {
        jmsTemplate.send(mqDestination, session -> {
            BytesMessage message = session.createBytesMessage();
            message.setStringProperty("simNumber", ID);
            message.writeBytes(body);
            return message;
        });
        LOGGER.info(Thread.currentThread().getName() + " 向队列" + mqDestination.toString());
        LOGGER.info("FTP文件上传完成  sim卡号-------->" + ID);
        LOGGER.info("消息体内容 -------->" + body);
    }
}
